import http from "../../../utils/http"
import util from "../../../utils/util"
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    list:[],
    finish: false,
    loading: false,
    page: 1,
    info:{}
  },

  onChange(e){
    this.setData({
      active: e.detail.index
    })
    this.reload()
  },
  reload(){
    this.setData({
      list: [],
      page: 1,
      finish: false
    })
    this.getList()
  },
  more(){
    this.setData({
      page: ++this.data.page
    })
    this.getList()
  },
  getList(){
    if(this.data.finish){
      return 
    }
    if(this.data.loading){
      return 
    }
    this.setData({
      loading: true
    })
    let data = {
      page: this.data.page,
      type: 'all',
      date: '2024/7/17-2099/12/31',
    }
    if(this.data.active === 0){
      data['type'] = 'all'
    }else if(this.data.active === 1){
      data['type'] = 'yes'
    }else if(this.data.active === 2){
      data['type'] = 'back'
    }else if(this.data.active === 3){
      data['type'] = 'cancel'
    }
    http.get('/addons/shopro/commission.order/index', data).then(res => {
      if(res.data.orders.data.length === 0){
        this.setData({
          finish: true
        })
      }
      let arr = this.data.list.concat(res.data.orders.data)
      this.setData({
        list: arr
      })
    }).finally(res => {
      this.setData({
        loading: false
      })
    })
  },
  getInfo(){
    http.post('/addons/shopro/commission.agent/info').then(res => {
      this.setData({
        info: res.data
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      active: options.active ?  Number(options.active) : 0,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getInfo()
    this.reload()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})